package com.smartleanx.module.hrm.controller.admin.esign.docTemp;


import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.module.hrm.service.esign.eums.FolderTypeEnum;
import com.smartleanx.module.hrm.service.esign.temp.ESignDocTempService;
import com.smartleanx.module.hrm.service.esign.temp.param.HrmEContractTempFileParam;
import com.smartleanx.module.hrm.service.esign.temp.param.HrmEContractTempParam;
import com.smartleanx.module.hrm.service.esign.temp.po.HrmEFolder;
import com.smartleanx.module.hrm.service.esign.temp.result.HrmContractCodeResult;
import com.smartleanx.module.hrm.service.esign.temp.result.HrmEFilesResult;
import com.smartleanx.module.hrm.service.esign.temp.vo.HrmEContractTempVo;
import com.smartleanx.module.hrm.service.esign.temp.vo.SignFlowCreateVo;
import com.smartleanx.module.hrm.util.esign.EsignHttpHelper;
import com.smartleanx.module.hrm.util.esign.EsignHttpResponse;
import com.smartleanx.module.hrm.util.esign.FileUtil;
import com.smartleanx.module.hrm.util.esign.enums.EsignRequestType;
import com.smartleanx.module.hrm.util.esign.exception.EsignDemoException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Tag(name =  "模板")
@RestController
@RequestMapping("/hrm/esign/docTemp")
public class ESignDocTempController {

//    @Autowired
//    private ESignAuthService eSignAuthService;

    @Autowired
    private ESignDocTempService eSignDocTempService;


    private final Boolean debug = true;

    @Operation(summary = "调用接口")
    @GetMapping("/getUrl")
    public EsignHttpResponse getUrl() {
        String eSignHost = "https://smlopenapi.esign.cn";
        String apiaddr="/v3/custom-components/create";
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;
        String psnId="af692e9326774e05923fc8a0c100d9f4";


        JSONObject parram = new JSONObject();
        JSONArray jsonAr = new JSONArray();

        JSONObject json = new JSONObject();
        json.set("componentName","自定义控件");
        json.set("customBizNum","xxx111");
        json.set("componentType","1");
        jsonAr.put(json);
        parram.set("components",jsonAr);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,debug);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, debug);

            return esignHttpResponse;

        } catch (EsignDemoException e) {
            e.printStackTrace();
        }


        return null;

//
//        String eSignAppId = "7439042143";
//        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
//        String orgId="5ac8ade5a31d46338eade664e3681d85";
//        String eSignHost = "https://smlopenapi.esign.cn";
//
//        String apiaddr="/v3/seals/org-seals/create-by-template";
//        //请求参数body体,json格式。get或者delete请求时jsonString传空json:"{}"或者null
//        String jsonParm="{\n" +
//                "  \"orgId\": \""+orgId+"\",\n" +
//                "  \"sealName\": \"企业公章1\",\n" +
//                "  \"sealTemplateStyle\": \"PERSONNEL_ROUND_NO_STAR\",\n" +
//                "  \"sealOpacity\": \"100\",\n" +
//                "  \"sealColor\": \"RED\",\n" +
//                "  \"sealOldStyle\": \"OLD_12\",\n" +
//                "  \"sealSize\":\"38_38\"\n" +
//                "}";
//        //请求方法
//        EsignRequestType requestType= EsignRequestType.POST;
//        //生成签名鉴权方式的的header
//        Map<String, String> header = null;
//        try {
//            header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
//            return EsignHttpHelper.doCommHttp(eSignHost, apiaddr,requestType , jsonParm, header,true);
//
//        } catch (EsignDemoException e) {
//            e.printStackTrace();
//        }
//        //发起接口请求
//        return null;
    }

    public static void main(String[] args) {
        setA4();
//        String format = DateUtil.format(new Date(), "yyyy/mm/dd");
//        System.out.println(format);
    }

    //查询控件列表
    public static void setA1(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String apiaddr="/v3/custom-components/get-list";
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;
        String psnId="af692e9326774e05923fc8a0c100d9f4";


        JSONObject parram = new JSONObject();
        parram.set("pageNum","1");
        parram.set("pageSize","10");
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //添加控件组
    public static void setA2(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String apiaddr="/v3/custom-component-group/create";
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;
        String psnId="af692e9326774e05923fc8a0c100d9f4";


        JSONObject parram = new JSONObject();
        parram.set("componentGroupName","控件组1");
        parram.set("componentGroupOrder","1");
        JSONArray jsonArray = new JSONArray();
        JSONObject json = new JSONObject();
        json.set("componentId","712c1335fa4a466bbc8ff8c028dcb364");
        jsonArray.set(json);
        parram.set("components",jsonArray);

        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //获取创建流程页面
    public static void setA3(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String apiaddr="/v3/sign-templates/sign-template-create-url";
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;
        String psnId="af692e9326774e05923fc8a0c100d9f4";


        JSONObject parram = new JSONObject();
        parram.set("orgId","5ac8ade5a31d46338eade664e3681d85");
        parram.set("transactorPsnId",psnId);
        parram.set("redirectUrl","www.baidu.com");
        parram.set("hiddenOriginComponents",true);
        JSONArray customComponentGroups = new JSONArray();
        customComponentGroups.set("21c5d740f7ac4e0997e9370ce5ea3c87");
        JSONArray customComponents = new JSONArray();
        customComponents.set("712c1335fa4a466bbc8ff8c028dcb364");
        parram.set("customComponents",customComponents);
        parram.set("customComponentGroups",customComponentGroups);

        JSONArray uneditableFields = new JSONArray();
        uneditableFields.set("participants");
        uneditableFields.set("docs");
        parram.set("uneditableFields",uneditableFields);

        JSONArray fileIds = new JSONArray();
        fileIds.set("69eb3ed6fc4443e2bfe8e3de37d76f0b");
        parram.set("fileIds",fileIds);


        JSONArray participants = new JSONArray();
        JSONObject item = new JSONObject();
        item.set("participantFlag","甲方");
        item.set("participantType","1");
        item.set("participateBizType","1,2");
        item.set("participantSetMode",1);
        item.set("signOrder",1);
        item.set("draftOrder",1);
        JSONObject orgParticipant = new JSONObject();
        orgParticipant.set("orgName","青岛劳安智心");
        JSONObject transactor = new JSONObject();
        transactor.set("transactorPsnAccount","17684726605");
        transactor.set("transactorName","杨力豪");
        orgParticipant.set("transactor",transactor);
        item.set("orgParticipant",orgParticipant);
        participants.add(item);

        parram.set("participants",participants);

        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //创建文件模板
    public static void setA4(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String apiaddr="/v3/doc-templates/doc-template-create-url";
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址
        String filePath="http://file.laoanxin.top/laoanxin-show-1326444324/e8e9a1cc6a091239edaf1334b64b85818535fc6b3d4d004309c8b1137aa49547.pdf";
//        String filePath="https://laoanxin-1307778067.cos.ap-beijing.myqcloud.com/loadFile/tmp_93d4e68328be895f71ffa24c8da811b12338423084008080515docx.doc";
        String fileId = "";
        try {
            fileId = FileUtil.fileHTML(filePath);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String psnId="af692e9326774e05923fc8a0c100d9f4";

        JSONObject parram = new JSONObject();
        parram.set("docTemplateName","文件接口合同222");
        parram.set("docTemplateType","1");
        parram.set("redirectUrl","http://www.baidu.com");
        parram.set("fileId",fileId);
        JSONArray customComponentGroups = new JSONArray();
        customComponentGroups.set("21c5d740f7ac4e0997e9370ce5ea3c87");
        JSONArray customComponents = new JSONArray();
        customComponents.set("712c1335fa4a466bbc8ff8c028dcb364");
        parram.set("customComponents",customComponents);
        parram.set("customComponentGroups",customComponentGroups);
        JSONArray signerRoles = new JSONArray();
        signerRoles.put("企业");
        signerRoles.put("员工");
        parram.set("signerRoles",signerRoles);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }


    //合同发起签署
    public static void setA5(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String apiaddr="/v3/sign-flow/create-by-file";
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //pdf格式文件
        String fileId = "e4d0e2878fee403a9345327fb5e84295";
//        try {
//            fileId = FileUtil.fileHTML(filePath);
//        } catch (EsignDemoException e) {
//            e.printStackTrace();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        SignFlowCreateVo signFlowCreateBo = new SignFlowCreateVo();

        //1. 带签署文件
        List<SignFlowCreateVo.DocItem> docs = new ArrayList<>();
        SignFlowCreateVo.DocItem docItem = new SignFlowCreateVo.DocItem();
        docItem.setFileId(fileId);
        docs.add(docItem);
        signFlowCreateBo.setDocs(docs);

        //2. 流程配置
        SignFlowCreateVo.SignFlowConfig signFlowConfig = new SignFlowCreateVo.SignFlowConfig();
        signFlowConfig.setSignFlowTitle("文件发起测试");

        signFlowConfig.setAutoFinish(false);
        signFlowConfig.setSignFlowExpireTime(1754806899000L);
        signFlowCreateBo.setSignFlowConfig(signFlowConfig);
        //3. 签署信息
        List<SignFlowCreateVo.SignerItem> signers = new ArrayList<>();
        SignFlowCreateVo.SignerItem corpSignerItem = new SignFlowCreateVo.SignerItem();
        corpSignerItem.setSignerType(1);

        SignFlowCreateVo.SignerItem.SignConfig signConfig = new SignFlowCreateVo.SignerItem.SignConfig();
        signConfig.setSignOrder(2);
        corpSignerItem.setSignConfig(signConfig);

        List<SignFlowCreateVo.SignerItem.SignFields> signFields = new ArrayList<>();
        SignFlowCreateVo.SignerItem.SignFields signFieldItem = new SignFlowCreateVo.SignerItem.SignFields();
        signFieldItem.setFileId(fileId);
        signFieldItem.setCustomBizNum("xxx123456");
        SignFlowCreateVo.SignerItem.SignFields.NormalSignFieldConfig normalSignFieldConfig = new SignFlowCreateVo.SignerItem.SignFields.NormalSignFieldConfig();
        normalSignFieldConfig.setSignFieldStyle(1);
//        normalSignFieldConfig.setFreeMode(true);
//        normalSignFieldConfig.setAutoSign(true);
//        normalSignFieldConfig.setAssignedSealId("3503202e-908f-428f-85bf-e9948e559a27");
        SignFlowCreateVo.SignerItem.SignFields.NormalSignFieldConfig.SignFieldPosition signFieldPosition = new SignFlowCreateVo.SignerItem.SignFields.NormalSignFieldConfig.SignFieldPosition();
        signFieldPosition.setPositionX(114.372375f);
        signFieldPosition.setPositionY(446.88156f);
        signFieldPosition.setPositionPage(1);
        normalSignFieldConfig.setSignFieldPosition(signFieldPosition);
        //自动落章需要注释的参数
        SignFlowCreateVo.SignerItem.OrgSignerInfo orgSignerInfo = new SignFlowCreateVo.SignerItem.OrgSignerInfo();
        orgSignerInfo.setOrgName("青岛劳安智心科技有限公司");
        SignFlowCreateVo.SignerItem.OrgSignerInfo.TransactorInfo transactorInfo = new SignFlowCreateVo.SignerItem.OrgSignerInfo.TransactorInfo();
        transactorInfo.setPsnAccount("18259479681");
        SignFlowCreateVo.SignerItem.OrgSignerInfo.TransactorInfo.PsnInfo psnInfo1 = new SignFlowCreateVo.SignerItem.OrgSignerInfo.TransactorInfo.PsnInfo();
        psnInfo1.setPsnName("肖泽强");
        transactorInfo.setPsnInfo(psnInfo1);
        orgSignerInfo.setTransactorInfo(transactorInfo);

        corpSignerItem.setOrgSignerInfo(orgSignerInfo);

        //结束
        signFieldItem.setNormalSignFieldConfig(normalSignFieldConfig);
        signFields.add(signFieldItem);

        corpSignerItem.setSignFields(signFields);

        signers.add(corpSignerItem);

        SignFlowCreateVo.SignerItem psnSignerItem = new SignFlowCreateVo.SignerItem();
        psnSignerItem.setSignerType(0);

        SignFlowCreateVo.SignerItem.SignConfig psnsignConfig = new SignFlowCreateVo.SignerItem.SignConfig();
        psnsignConfig.setSignOrder(1);
        psnSignerItem.setSignConfig(psnsignConfig);

        List<SignFlowCreateVo.SignerItem.SignFields> psnSignFields = new ArrayList<>();
        SignFlowCreateVo.SignerItem.SignFields psnsignFieldItem = new SignFlowCreateVo.SignerItem.SignFields();
        psnsignFieldItem.setFileId(fileId);
        psnsignFieldItem.setCustomBizNum("xxx123456");

        SignFlowCreateVo.SignerItem.PsnSignerInfo psnSignerInfo = new SignFlowCreateVo.SignerItem.PsnSignerInfo();
        psnSignerInfo.setPsnAccount("18259479681");
        SignFlowCreateVo.SignerItem.PsnSignerInfo.PsnInfo psnInfo = new SignFlowCreateVo.SignerItem.PsnSignerInfo.PsnInfo();
        psnInfo.setPsnName("肖泽强");
        psnSignerInfo.setPsnInfo(psnInfo);
        psnSignerItem.setPsnSignerInfo(psnSignerInfo);

        SignFlowCreateVo.SignerItem.SignFields.NormalSignFieldConfig psnnormalSignFieldConfig = new SignFlowCreateVo.SignerItem.SignFields.NormalSignFieldConfig();
        psnnormalSignFieldConfig.setSignFieldStyle(1);
        SignFlowCreateVo.SignerItem.SignFields.NormalSignFieldConfig.SignFieldPosition position = new SignFlowCreateVo.SignerItem.SignFields.NormalSignFieldConfig.SignFieldPosition();
        position.setPositionX(289.84106f);
        position.setPositionY(485.13153f);
        position.setPositionPage(1);
        psnnormalSignFieldConfig.setSignFieldPosition(position);
        psnsignFieldItem.setNormalSignFieldConfig(psnnormalSignFieldConfig);

        psnSignFields.add(psnsignFieldItem);

        psnSignerItem.setSignFields(psnSignFields);
        signers.add(psnSignerItem);
        signFlowCreateBo.setSigners(signers);

        String jsonParm = new JSONObject(signFlowCreateBo).toString();
        System.out.println("===============");
        System.out.println(new JSONObject(signFlowCreateBo).toString());


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }


    //文件上传
    public static void setA6(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String apiaddr="/v3/files/get-seal-position-url";
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址
        String filePath="C:\\Users\\Administrator\\Desktop\\合同文档.docx";
        String fileId = "69eb3ed6fc4443e2bfe8e3de37d76f0b";
//        try {
//            fileId = FileUtil.fileHTML(filePath);
//        } catch (EsignDemoException e) {
//            e.printStackTrace();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        String psnId="af692e9326774e05923fc8a0c100d9f4";

        JSONObject parram = new JSONObject();
        parram.set("docTemplateName","文件接口合同");
        parram.set("docTemplateType","1");
        parram.set("redirectUrl","http://www.baidu.com");
        parram.set("fileId",fileId);
        JSONArray customComponentGroups = new JSONArray();
        customComponentGroups.set("21c5d740f7ac4e0997e9370ce5ea3c87");
        JSONArray customComponents = new JSONArray();
        customComponents.set("712c1335fa4a466bbc8ff8c028dcb364");
        parram.set("customComponents",customComponents);
        parram.set("customComponentGroups",customComponentGroups);
        JSONArray signerRoles = new JSONArray();
        signerRoles.put("甲方");
        signerRoles.put("乙方");
        parram.set("signerRoles",signerRoles);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //文件转换
    public static void setA7(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String apiaddr="/v3/files/create-by-doc-template";
        String tempId = "adedd4adafad466d9cb69456c1647607";
        String fileName = "文件合同dpf";
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址

        JSONObject parram = new JSONObject();
        parram.set("docTemplateId",tempId);
        parram.set("fileName",fileName);
        JSONArray components = new JSONArray();
        JSONObject comItem = new JSONObject();
        comItem.set("componentId","4834d3c3a87d4baf9ce4ee0fbe384f4f");
        comItem.set("componentValue","--");
        components.add(comItem);
        parram.set("components",components);
        parram.set("requiredCheck",false);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //获取填写页面
    public static void setA10(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String apiaddr="/v3/doc-templates/doc-template-fill-url";
        String docTemplateId = "adedd4adafad466d9cb69456c1647607";
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址

        JSONObject parram = new JSONObject();
        parram.set("docTemplateId",docTemplateId);

        JSONArray componentFillingtValues = new JSONArray();
//        JSONObject item = new JSONObject();
//        item.set("componentId","4834d3c3a87d4baf9ce4ee0fbe384f4f");
//        item.set("componentValue","自动回显");
//        componentFillingtValues.add(item);
        parram.set("componentFillingtValues",componentFillingtValues);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //查询HTML填写后的文件
    public static void setA11(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String fileId = "06572888c03b404bbd76a3ca5a030163";
        String apiaddr="/v3/files/"+fileId+"/detail";
        //请求方法
        EsignRequestType requestType= EsignRequestType.GET;

        //获取文件id以及文件上传地址

        JSONObject parram = new JSONObject();
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

//    //查询PDF填写后的文件
//    public static void setA12(){
//        String eSignHost = "https://smlopenapi.esign.cn";
//        String fileId = "0dba00d1258649c9bc9f082dd38cd799";
//        String apiaddr="/v3/files/"+fileId+"/detail";
//        //请求方法
//        EsignRequestType requestType= EsignRequestType.GET;
//
//        //获取文件id以及文件上传地址
//
//        JSONObject parram = new JSONObject();
//        String jsonParm=parram.toString();
//
//
//        //生成签名鉴权方式的的header
//        String eSignAppId = "7439042143";
//        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
//        try {
//            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
//            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
//        } catch (EsignDemoException e) {
//            e.printStackTrace();
//        }
//    }

    //查询模板控件
    public static void setA8(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String tempId = "adedd4adafad466d9cb69456c1647607";
        String apiaddr="/v3/doc-templates/"+tempId;
        String fileName = "文件合同dpf";
        //请求方法
        EsignRequestType requestType= EsignRequestType.GET;

        //获取文件id以及文件上传地址

        JSONObject parram = new JSONObject();
//        parram.set("docTemplateId",tempId);
//        parram.set("fileName",fileName);
//        JSONArray components = new JSONArray();
//        parram.set("components",components);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }
//f99058e7f83b441ebdb03c71b0e89b16  流程id
    //获取签署链接
    public static void setA9(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String signFlowId = "0c87082709c543bf912f185e97e449df";
        String apiaddr="/v3/sign-flow/"+signFlowId+"/sign-url";
        System.out.println("请求路径:"+apiaddr);
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址

        JSONObject parram = new JSONObject();
        JSONObject operator = new JSONObject();
//        17684726605  13220866005
        operator.set("psnAccount","18259479681");
        parram.set("operator",operator);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //撤回签署流程
    public static void setA18(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String signFlowId = "86363f897ba747b2bf40fc81152e11f9";
        String apiaddr="/v3/sign-flow/"+signFlowId+"/revoke";
        System.out.println("请求路径:"+apiaddr);
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址

        JSONObject parram = new JSONObject();
        JSONObject operator = new JSONObject();
//        17684726605  13220866005
        operator.set("psnAccount","18259479681");
        parram.set("operator",operator);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //追加附件
    public static void setA13(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String signFlowId = "08f2d7e367784286b60232f15e6dd59d";
        String apiaddr="/v3/sign-flow/"+signFlowId+"/attachments";
        System.out.println("请求路径:"+apiaddr);
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址

        JSONObject parram = new JSONObject();
        JSONArray attachmentList = new JSONArray();
        JSONObject item = new JSONObject();
        item.set("fileId","0dba00d1258649c9bc9f082dd38cd799");
//        item.set("fileName","0dba00d1258649c9bc9f082dd38cd799");
        attachmentList.add(item);
        parram.set("attachmentList",attachmentList);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //出证
    public static void setA14(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String signFlowId = "e584e49c07694d5eaf91ff8a2272d911";
        String apiaddr="/v3/evidence-report/apply";
        System.out.println("请求路径:"+apiaddr);
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址

        JSONObject parram = new JSONObject();
        parram.set("signFlowId",signFlowId);
        parram.set("reportType","TSIGN_REPORT");
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //获取填写任务结果
    public static void setA15(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String docTempId = "adedd4adafad466d9cb69456c1647607";
        String fillTaskId = "5458a77930c04b1bb2bc77adb71a0b3b";
        String apiaddr="/v3/doc-templates/fill-task-result";
        System.out.println("请求路径:"+apiaddr);
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址

        JSONObject parram = new JSONObject();
        parram.set("docTemplateId",docTempId);
        parram.set("fillTaskId",fillTaskId);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //获取预览合同模板页面
    public static void setA16(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String docTemplateId = "0f2b8d14cdd04ce1acb072570de3e79a";
        String apiaddr="/v3/doc-templates/doc-template-preview-url";
        System.out.println("请求路径:"+apiaddr);
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址

        JSONObject parram = new JSONObject();
        parram.set("docTemplateId",docTemplateId);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //获取合同模板中控件详情
    public static void setA17(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String docTemplateId = "adedd4adafad466d9cb69456c1647607";
        String apiaddr="/v3/doc-templates/"+docTemplateId;
        System.out.println("请求路径:"+apiaddr);
        //请求方法
        EsignRequestType requestType= EsignRequestType.GET;

        //获取文件id以及文件上传地址

        JSONObject parram = new JSONObject();
//        parram.set("docTemplateId",docTemplateId);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //添加抄送
    public static void setA19(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String signFlowId = "0c87082709c543bf912f185e97e449df";
        String apiaddr="/v3/sign-flow/"+signFlowId+"/copiers";
        System.out.println("请求路径:"+apiaddr);
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址
        JSONObject parram = new JSONObject();
        JSONArray copiers = new JSONArray();
        JSONObject copierPsnInfo = new JSONObject();
        JSONObject copierParam = new JSONObject();
        copierPsnInfo.set("psnAccount","18259479681");
        copierParam.set("copierPsnInfo",copierPsnInfo);
        copiers.add(copierParam);
        parram.set("copiers",copiers);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }


    //填写模板生成文件
    public static void setA20(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String docTemplateId = "0c87082709c543bf912f185e97e449df";
        String apiaddr="/v3/files/create-by-doc-template";
        String fileName="阿萨德";
        System.out.println("请求路径:"+apiaddr);
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址
        JSONObject parram = new JSONObject();
        JSONArray copiers = new JSONArray();
        JSONObject copierPsnInfo = new JSONObject();
        JSONObject copierParam = new JSONObject();
        copierPsnInfo.set("psnAccount","18259479681");
        copierParam.set("copierPsnInfo",copierPsnInfo);
        copiers.add(copierParam);
        parram.set("copiers",copiers);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    //个人认证授权
    public static void setA21(){
        String eSignHost = "https://smlopenapi.esign.cn";
        String apiaddr="/v3/psn-auth-url";
        System.out.println("请求路径:"+apiaddr);
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址
        JSONObject parram = new JSONObject();
        JSONObject psnAuthConfig = new JSONObject();
        psnAuthConfig.set("psnAccount","18259479681");
        parram.set("psnAuthConfig",psnAuthConfig);
        JSONObject redirectConfig = new JSONObject();
        redirectConfig.set("redirectConfig","https://www.baidu.com");
        parram.set("redirectConfig",redirectConfig);
        JSONObject authorizeConfig = new JSONObject();
        JSONArray authorizedScopes = new JSONArray();
        authorizedScopes.add("get_psn_identity_info");
        authorizeConfig.set("authorizedScopes",authorizedScopes);
        parram.set("authorizeConfig",authorizeConfig);
        String jsonParm=parram.toString();


        //生成签名鉴权方式的的header
        String eSignAppId = "7439042143";
        String eSignAppSecret = "77903a458d7fa6a9a4818856966ab1d1";
        try {
            Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
            EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
        } catch (EsignDemoException e) {
            e.printStackTrace();
        }
    }

    @Operation(summary = "删除自定义控件")
    @PostMapping("/removeEsignComponent")
    public void removeEsignComponent() {
        eSignDocTempService.removeEsignComponent();
    }

    @Operation(summary = "获取自定义控件")
    @GetMapping("/getEsignComponent")
    public void getEsignComponent() {
        eSignDocTempService.getEsignComponent();
    }

    @Operation(summary = "添加自定义控件")
    @PostMapping("/saveComponentToEsign")
    public void saveComponentToEsign() {
        eSignDocTempService.saveComponentToEsign();
    }

    @Operation(summary = "上传文件")
    @PostMapping("/uploadFile")
    public CommonResult<String> uploadFile(@RequestBody HrmEContractTempFileParam fileParam) {
        return CommonResult.success(eSignDocTempService.uploadFile(fileParam)).setCode(200);
    }

    @Operation(summary = "获取编码生成规则")
    @GetMapping("/getContractCodeData")
    public CommonResult<List<HrmContractCodeResult>> getContractCodeData(Long tempId) {
        return CommonResult.success(eSignDocTempService.getContractCodeData(tempId)).setCode(200);
    }

    @Operation(summary = "获取员工附件")
    @GetMapping("/getFiles")
    public CommonResult<List<HrmEFilesResult>> getFiles() {
        return CommonResult.success(eSignDocTempService.getFiles()).setCode(200);
    }

    @Operation(summary = "保存模板信息")
    @PostMapping("/saveDocTemp")
    public CommonResult saveDocTemp(@RequestBody HrmEContractTempVo hrmEContractTempVo) {
        return CommonResult.success(eSignDocTempService.saveDocTemp(hrmEContractTempVo)).setCode(200);
    }

    @Operation(summary = "获取模板列表")
    @GetMapping("/getDocTempPage")
    public CommonResult getDocTempPage(HrmEContractTempParam param) {
        return CommonResult.success(eSignDocTempService.getDocTempPage(param)).setCode(200);
    }

    @Operation(summary = "获取模板详情")
    @GetMapping("/getDocTempDetail")
    public CommonResult getDocTempDetail(@RequestParam("id") Long id) {
        return CommonResult.success(eSignDocTempService.getDocTempDetail(id)).setCode(200);
    }

    @Operation(summary = "修改模板")
    @PostMapping("/updateDocTemp")
    public CommonResult updateDocTemp(@RequestBody HrmEContractTempVo param) {
        return CommonResult.success(eSignDocTempService.updateDocTemp(param)).setCode(200);
    }

    @Operation(summary = "启用停用模板")
    @PostMapping("/updateDocTempStatus")
    public CommonResult updateDocTempStatus(@RequestBody HrmEContractTempParam param) {
        return CommonResult.success(eSignDocTempService.updateDocTempStatus(param)).setCode(200);
    }

    @Operation(summary = "删除模板")
    @PostMapping("/removeDocTemp")
    public CommonResult removeDocTemp(HrmEContractTempParam param) {
        return CommonResult.success(eSignDocTempService.removeDocTemp(param)).setCode(200);
    }

    @Operation(summary = "添加分组")
    @PostMapping("/saveFolder")
    public CommonResult saveFolder(@RequestBody HrmEFolder param) {
        param.setFolderType(FolderTypeEnum.GROUP.getCode());
        param.setDataStatus(1);
        return CommonResult.success(eSignDocTempService.saveFolder(param)).setCode(200);
    }

    @Operation(summary = "修改分组")
    @PostMapping("/updateFolder")
    public CommonResult updateFolder(@RequestBody HrmEFolder param) {
        return CommonResult.success(eSignDocTempService.updateFolder(param)).setCode(200);
    }

    @Operation(summary = "删除分组")
    @PostMapping("/removeFolder")
    public CommonResult removeFolder(@RequestBody HrmEFolder param) {
        return CommonResult.success(eSignDocTempService.removeFolder(param)).setCode(200);
    }

    @Operation(summary = "获取分组详情")
    @GetMapping("/getFolderDetail")
    public CommonResult getFolderDetail(@RequestParam("id") Long id) {
        return CommonResult.success(eSignDocTempService.getFolderDetail(id)).setCode(200);
    }

    @Operation(summary = "查询分组")
    @GetMapping("/getFolderResult")
    public CommonResult getFolderResult() {
        return CommonResult.success(eSignDocTempService.getFolderResult(FolderTypeEnum.GROUP.getCode())).setCode(200);
    }

    @Operation(summary = "查询父级列表")
    @GetMapping("/getParentFolderResult")
    public CommonResult getParentFolderResult() {
        return CommonResult.success(eSignDocTempService.getParentFolderResult(FolderTypeEnum.GROUP.getCode())).setCode(200);
    }

    @Operation(summary = "获取轮询状态")
    @GetMapping("/getSaveUpdateStatus")
    public CommonResult getSaveUpdateStatus(String tempSignId) {
        return CommonResult.success(eSignDocTempService.getSaveUpdateStatus(tempSignId)).setCode(200);
    }

}
